﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

using LRSTaxServices.Biz;

public partial class AdminLRS_Default : System.Web.UI.Page
{
    #region Event Handlers

    #region Page Load

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            ViewState["UserName"] = null;
            ViewState["OriginalPassword"] = null;
            lblfeedback.Visible = false;
            username.Attributes.Add("onFocus", "clearclienttext()");
            username.Attributes.Add("onBlur", "setclienttext()");
            txtpassword.Attributes.Add("onFocus", "clearclientpassword()");
            txtpassword.Attributes.Add("onBlur", "setclientpassword()");
        }
    }

    #endregion

    #region Button Clicks

    protected void imgbtncancel_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("#");
    }

    protected void imgbtnsubmit_Click(object sender, ImageClickEventArgs e)
    {
        //to do process login request...
        string errMsg = "";
        SubAdmin.RbsError result = SubAdmin.LogonUser(username.Text, txtpassword.Text, out errMsg);
        Session["Password_Change_Required"] = null;
        if (result == SubAdmin.RbsError.PASSWORD_CHANGE_REQUIRED)
        {
            ViewState["UserName"] = username.Text;  // Retain the UserName in the page's ViewState.
            ViewState["OriginalPassword"] = txtpassword.Text;  // Retain the original Password in the page's ViewState.
            Session["Password_Change_Required"] = "True";
            Session["username"] = username.Text;
            Response.Redirect("Dashboard.aspx");

        }
        Session["username"] = username.Text;
        Session["Password_Change_Required"] = "False";
        ProcessLogonResult(result, errMsg);
    }

    #endregion

    #endregion

    #region Privates

    #region ProcessLogonResult

    private void ProcessLogonResult(SubAdmin.RbsError result, string errMsg)
    {
        //divfeedback.Visible = true;
        lblfeedback.Visible = true;
        switch (result)
        {
            case SubAdmin.RbsError.NO_ERROR:
                Response.Redirect("DashBoard.aspx");
                break;

            case SubAdmin.RbsError.ACCOUNT_INACTIVE:
                lblfeedback.Text = "This Login ID is no longer active.  Please contact your Intrepid Services Technical Support or your Company Administrator for further assistance.";
                break;

            case SubAdmin.RbsError.ACCOUNT_LOCKED_OUT:
                break;

            case SubAdmin.RbsError.NO_RECORDS_FOUND:
                lblfeedback.Text = "The specified user cannot be found. Please contact the System Administrator for further assistence.";
                break;

            case SubAdmin.RbsError.INVALID_USERID:
                lblfeedback.Text = "The Login ID is invalid. Please try again.";
                break;

            case SubAdmin.RbsError.INVALID_USERNAME:
                lblfeedback.Text = "The Login ID is invalid. Please try again.";
                break;

            case SubAdmin.RbsError.INVALID_CREDENTIALS:
                lblfeedback.Text = "The Login ID/Password combination is invalid. Please try again.";
                break;

            case SubAdmin.RbsError.ACCOUNT_PENDING:
                lblfeedback.Text = "The Account you are attempting to login does not have an Active account status.  Please contact your Technical Support or the Administrator for further assistance.";
                break;

            case SubAdmin.RbsError.USER_NO_ROLES:
                lblfeedback.Text = "This user has not been assigned any roles.  Please contact your Technical Support or the Administrator for further assistance.";
                break;

            case SubAdmin.RbsError.OTHER_EXCEPTION:
                lblfeedback.Text = errMsg;
                break;
        }
    }

    #endregion

    #endregion
}
